<?php
/**
 * Created by PhpStorm.
 * User: yys
 * Date: 2016/12/8
 * Time: 17:44
 */

namespace App\Services\GiftService;


use Illuminate\Support\Facades\DB;

class GiftTool
{
    /***
     * 获取赠品已绑定优惠资源
     * @param $gift_id
     * @param int $state
     * @return array
     */
      public static function getSimpleRegsByGiftId($gift_id,$state=1){
        if(empty($gift_id)||!is_int($gift_id)){
            return array();
        }
        $query=DB::table('favorable_gifts')->where(array('gift_id'=>$gift_id));
        if($state===1){
            $query->where('state',1);
        }
        $favorable_gifts=$query->select('reg_id','use_range','type')->get()->toArray();
        return empty($favorable_gifts)?array():$favorable_gifts;
      }

    /***
     * 产品id获取产品模板id
     * @param $product_id
     * @param int $state
     * @return string
     */
    public static function getProductTempIdByProductId($product_id,$state=1){
        if(empty($product_id)){
            return '';
        }
        $query=DB::table('products')->where(array('product_id'=>$product_id));
        if($state===1){
            $query->where('state',1);
        }
        $product_temp_id=$query->value('product_temp_id');
        return empty($product_temp_id)?'':$product_temp_id;
    }
}